#ifndef TIMOGRAM_HPP
#define TIMOGRAM_HPP

#include <vector>

namespace Dynamic
{

struct SystemMatrix;
struct TimedVoxels;
struct MaterialTable;

//
// LOR array
//
// addressed by discretized polar angle of the first and the difference to the other end

struct ListModeEvent {
	// Time
	double t_e;

	// Result of the forward projection
	double lambda_Le;

	ListModeEvent();
};

struct Timogram {
	// nlor pieces of vectors which comprise time moment of events and lambda
	std::vector<ListModeEvent>* array;
public:
	Timogram();

	Timogram(const Timogram& v);

	~Timogram();

	static int LorIndex(int iphi, int idphi);

	void operator=(const Timogram& m);

	void Clear();
	void Zero();
	void InitWithOneEvent(double t_e);

	void randomize(double measurementInterval, int numberOfEvents, SystemMatrix& A_LV, TimedVoxels& x, double activity);

	//
	// Monte Carlo simulation
	//
	void InitMonteCarlo(bool Zeromx, MaterialTable& mt, TimedVoxels& x, int Nsamples, double measurementInterval, 
		bool ScatteredOnly = false, bool Correction = true);

	//  void average( Lors& yComp, Lors& yTent, double tau ) {
	//      for ( unsigned int L = 0; L < nlors; ++L ) {
	//          array[L] = yComp.array[L] * (1.0-tau) + yTent.array[L] * tau;
	//      }
	//  }

	double sumEvents();
	double sumLambdaAccumulated();
	double sumLambda(int iphi, int idphi);
	double sumLambda(unsigned int lorIndex);

	//  void rejectSample( Lors& vMarkov, Lors& vTent ) {
	//      for ( unsigned int L = 0; L < nlors; ++L )  {
	//          if (vMarkov.array[L] > 0) {
	//              double a = vTent.array[L] / vMarkov.array[L];
	//              a = (a > 1) ? 1 : a;
	//              if ( a > rnd_0_1() && a > 0.05 ) array[L] = vTent.array[L];
	// //               if ( a > rnd_0_1() && a > 0.0 ) array[L] = vTent.array[L];
	//              else                             array[L] = vMarkov.array[L];
	//          } else array[L] = vTent.array[L];
	//      }
	//  }

	double MaxLambdaAccumulated();

	double MaxLambda();

	// QUESTION: Hogy adjuk meg ezt a sinogramot?
	void PrintSinogram(const char* ofname, double maxvalue, bool bar = false);
};
}

#endif // TIMOGRAM_HPP
